package com.tinywind.Sword.Service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.tinywind.Sword.Dao.TodoDao;
import com.tinywind.Sword.Dao.TodoUserDao;
import com.tinywind.Sword.Entity.TodoEntity;
import com.tinywind.Sword.Entity.TodoFilter;
import com.tinywind.Sword.Service.TodoService;

@Service
public class TodoServiceImpl implements TodoService {

//	private Logger logger = LoggerFactory.getLogger(this.getClass());

	// 注入Service依赖
	@Autowired
	private TodoDao dao;
	@Autowired
	private TodoUserDao mTodoUserDao;

	@Override
	public List<TodoEntity> search(TodoFilter filter) {
		return dao.search(filter);
	}

//	@Override
//	public Integer insert(TodoEntity entity) {
//		// TODO Auto-generated method stub
//		return dao.insert(entity);
//	}
	
	@Override
	@Transactional
	public Integer insert(TodoEntity todo,int userId) {
		
		dao.insert(todo);
		return mTodoUserDao.insert(todo.id, userId);
	}
	
	@Override
	public int getTotalCount(TodoFilter filter) {
		return  dao.getTotalCount(filter);
	}

	@Override
	public void update(TodoEntity entity) {
		// TODO Auto-generated method stub
		dao.update(entity);
		
	}

	@Override
	@Transactional
	public void delete(long todoId,int userId) {
		// TODO Auto-generated method stub
		dao.delete(todoId);
		mTodoUserDao.delete(todoId,userId);
	}

}
